package com.jp.knowledge.view.experience;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import com.anarchy.classify.simple.widget.BagDrawable;
import com.anarchy.classify.simple.widget.InsertAbleGridView;
import com.jp.knowledge.R;

import java.lang.reflect.Field;

/**
 * Created by 528787067@qq.com on 2017/2/9.
 */

public class ExperienceInsertAbleGridView extends SquareInsertAbleGridView {

    public ExperienceInsertAbleGridView(Context context) {
        this(context, null);
    }

    public ExperienceInsertAbleGridView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ExperienceInsertAbleGridView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SquareInsertAbleGridView);
        BagDrawable bagDrawable = new ExperienceBagDrawable(a.getDimensionPixelSize(R.styleable.InsertAbleGridView_OutlinePadding, 10));
        bagDrawable.setOutlineStyle(a.getColor(com.anarchy.classify.R.styleable.InsertAbleGridView_OutlineColor, 0), a.getDimensionPixelSize(com.anarchy.classify.R.styleable.InsertAbleGridView_OutlineWidth, 3));
        a.recycle();

        try {
            Field mBagDrawableField = InsertAbleGridView.class.getDeclaredField("mBagDrawable");
            mBagDrawableField.setAccessible(true);
            mBagDrawableField.set(this, bagDrawable);
            mBagDrawableField.setAccessible(false);
            setBackgroundDrawable(bagDrawable);
        } catch (Exception e) {
            return;
        }
    }
}
